package cn.pconline.autoclub.entity;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import java.util.Date;
import org.apache.commons.lang.StringUtils;
import org.gelivable.dao.Column;
import org.gelivable.dao.Entity;
import org.gelivable.dao.Id;
import org.gelivable.dao.Label;
import org.gelivable.dao.Transient;

/**
 * 风格样式
 *
 * @author zhoutianhuai
 */
@Entity(tableName = "ac_style", logChange = true)
public class Style {

    @Id
    @Column(name = "style_id")
    private long styleId;// 风格样式ID
    @Label(value = "风格样式内容")
    @Column(name = "style_content")
    private String styleContent;//风格样式内容，json格式{background":"xx","coverImage":"xx","css":"xx","showImage":"xx"}
    @Label(value = "级别")
    @Column(name = "level")
    private int level;
    @Label(value = "创建时间")
    @Column(name = "create_at")
    private Date createAt;
    @Label(value = "创建人")
    @Column(name = "create_by")
    private long createBy;
    @Label(value = "自定义类型")
    @Column(name = "type")
    private int type; //1：完整套装；2：封面套装；3：自定义套装
    @Label(value = "是否默认")
    @Column(name = "is_default")
    private int isDefault;
    /**
     * 创建车友会默认风格样式*
     */
    public static int STYLE_DEFAULT = 1;
    /**
     * 非默认风格样式*
     */
    public static int STYLE_NO_DEFAULT = 0;
    public static int STYLE_TYPE_TZ = 1;//完整套装
    public static int STYLE_TYPE_FM = 2;//封面套装
    public static int STYLE_TYPE_DY = 3;//自定义套装
    @Transient
    private String cssString;
    @Transient
    private String coverString;
    @Transient
    private String showImage;
    @Transient
    private String background;
    @Transient
    private String lineColor;
    @Transient
    private String formColor;
    @Transient
    private String txtColor;

    private JSONObject parseStyleContent() {
        try {
            return JSONObject.parseObject(styleContent);
        } catch (JSONException e) {
            return null;
        }
    }

    public String getCoverString() {
        if (StringUtils.isNotBlank(coverString)) {
            return coverString;
        } else {
            return parseStyleContent().getString(ClubStyle.COVERIMAGE);
        }
    }

    public void setCoverString(String coverString) {
        this.coverString = coverString;
    }

    public String getCssString() {
        if (StringUtils.isNotBlank(cssString)) {
            return cssString;
        } else {
            return parseStyleContent().getString(ClubStyle.CSS);
        }
    }

    public void setCssString(String cssString) {
        this.cssString = cssString;
    }

    public String getShowImage() {
        if (StringUtils.isNotBlank(showImage)) {
            return showImage;
        } else {
            return parseStyleContent().getString(ClubStyle.SHOWIMAGE);
        }
    }

    public void setShowImage(String showImage) {
        this.showImage = showImage;
    }

    public String getBackground() {
        if (StringUtils.isNotBlank(background)) {
            return background;
        } else {
            return parseStyleContent().getString(ClubStyle.BACKGROUND);
        }
    }

    public void setBackground(String background) {
        this.background = background;
    }

    public String getLineColor() {
        if (StringUtils.isNotBlank(lineColor)) {
            return lineColor;
        } else {
            return parseStyleContent().getString(ClubStyle.LINECOLOR);
        }
    }

    public void setLineColor(String lineColor) {
        this.lineColor = lineColor;
    }

    public String getFormColor() {
        if (StringUtils.isNotBlank(formColor)) {
            return formColor;
        } else {
            return parseStyleContent().getString(ClubStyle.FORMCOLOR);
        }
    }

    public void setFormColor(String formColor) {
        this.formColor = formColor;
    }

    public String getTxtColor() {
        if (StringUtils.isNotBlank(txtColor)) {
            return txtColor;
        } else {
            return parseStyleContent().getString(ClubStyle.TXTCOLOR);
        }
    }

    public void setTxtColor(String txtColor) {
        this.txtColor = txtColor;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public long getStyleId() {
        return styleId;
    }

    public void setStyleId(long styleId) {
        this.styleId = styleId;
    }

    public String getStyleContent() {
        return styleContent;
    }

    public void setStyleContent(String styleContent) {
        this.styleContent = styleContent;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public Date getCreateAt() {
        return createAt;
    }

    public void setCreateAt(Date createAt) {
        this.createAt = createAt;
    }

    public long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(long createBy) {
        this.createBy = createBy;
    }

    public int getIsDefault() {
        return isDefault;
    }

    public void setIsDefault(int isDefault) {
        this.isDefault = isDefault;
    }
}
